package org.applet.game.app.rpg.widgets;

import java.awt.Event;

import org.applet.game.framework.component.Panel;
import org.applet.game.framework.core.Container;
import org.applet.game.framework.util.ImageLoader;

public class ParcelPanel extends Container {

	Panel head;
	Panel body;
	
	public ParcelPanel()
	{
		head = new Panel(ImageLoader.loadImage("image/plate/ParcelHead.png"));
		head.setLocation(0, 0);
		this.add(head);
		body = new Panel(ImageLoader.loadImage("image/plate/ParcelBody.png"));
		body.setName("123");
		body.setLocation(0, 30);
		this.add(body);
		this.setSize(head.getWidth(), head.getHeight()+body.getHeight());
	}
	
	@Override
	public void init() {
		super.init();
	}

	boolean drag = false;
	@Override
	public boolean mouseDown(Event e) {
		setOnTop();
		if(head.contains(e.x, e.y))
		{
			lastX = e.x;
			lastY = e.y;
			captureMouse();
			drag = true;
			return false;
		}
		else
			return true;
	}
	@Override
	public boolean mouseReleased(Event e) {
		releaseMouse();
		drag = false;
		return super.mouseReleased(e);
	}
	
	int lastX = -1;
	int lastY = -1;
	@Override
	public boolean mouseDrag(Event e) {
		if(drag)
		{
			if(lastX != -1)
			{
				int ox = e.x-lastX;
				int oy = e.y-lastY;
				setLocation(x+ox, y+oy);
			}
			lastX = e.x;
			lastY = e.y;
			return false;
		}
		else
			return true;
	}
	
//	@Override
//	public void render(Graphics2D painter, ImageObserver observer) {
//		// TODO Auto-generated method stub
//		super.render(painter, observer);
//		//System.out.println(head.getX()+","+head.getY()+"<"+head.contains(lastX, lastY));
//	}
}
